﻿function CheckLoginID(v) {
  ajaxRead("/tools/ajax.aspx?t=chkTeacherLoginID&v=" + v, "GetSetRst(obj);");
}

function GetSetRst(obj) {
  var res = obj.getElementsByTagName('result');
  var rst;
  if (res[0] != null && res[0] != undefined) {
    if (res[0].childNodes.length > 1) {
      rst = res[0].childNodes[1].nodeValue;
    } else {
      rst = res[0].firstChild.nodeValue;
    }
  }
  if (rst == "1") {
    $("#chkLoginIDRst").html("该登录名已存在，请更换");
    $("#chkloginrst").val("1");
  } else {
    $("#chkLoginIDRst").html("");
    $("#chkloginrst").val("0");
  }
}

function CheckForm() {
  var loginid = $("#LoginIDTxt").val();
  var pwd = $("#PwdTxt").val();
  var name = $("#NameTxt").val();
  var chklogin = $("#chkloginrst").val();
  var authority = $("#AuthoritySlt").val();
  var act = $("#act").val();
  
  var err = false;

  var areaArr = [];
  var isChecked = false;
  var areaList = document.getElementsByName("AreaChb");
  for (var i = 0; i < areaList.length; i++) {
    if ($("#AreaChb_" + i)[0].checked) {
      isChecked = true;
      areaArr.push($("#AreaChb_" + i).val());
    }
  }

  if (!isChecked) {
    alert("请至少选择一个地区");
    err = true;
  }

  $("#area_v").val(areaArr);

  if (act == "n") {
    if (loginid == "" || pwd == "") {
      err = true;
    }
  }

  if (name == "" || chklogin == "1" || authority == "-1" || (authority == "2" && $("#ProjectSlt").val() == "-1")) {
    err = true;
  }

  if (err) {
    alert("必填项不能为空");
    return false;
  } else {
    return true;
  }
}


function Step(sid) {
  var form = document.getElementById("form1");
  var rst = false;
  switch (sid) {
    case 1:
      if (document.getElementById("LoginIDTxt").value != "") {
        form.action = "?act=l";
        rst = true;
      } else {
        alert("请填写登录名");
      }
      break;
    case 2:
      if (document.getElementById("AnswerTxt").value != "") {
        form.action = "?act=q";
        rst = true;
      } else {
        alert("请填写提示问题答案");
      }
      break;
    case 3:
      var pwd = document.getElementById("NewPwdTxt").value;
      var confirmPwd = document.getElementById("ConfirmNewPwdTxt").value;
      if (pwd != "" && confirmPwd != "" && pwd == confirmPwd && pwd.length >= 6 && pwd.length <= 12) {
        form.action = "?act=u";
        rst = true;
      } else {
        alert("请正确填写密码");
      }
      break;
    default: break;
  }
  return rst;
}

function ChangeInternal(v) {
  if (v == "2") {
    document.getElementById("project").style.display = "";
  } else {
    document.getElementById("project").style.display = "none";
  }
}
